package com.zhoug.zmui3demo.ui;

import android.os.Bundle;
import android.widget.Button;

import com.zhoug.zmui3.ZMUIRoundIndicatorView;
import com.zhoug.zmui3demo.R;

import java.security.SecureRandom;
import java.util.Random;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @Author 35574
 * @Date 2022/4/18
 * @Description
 */
public class RoundIndicatorViewActivity extends AppCompatActivity {

    private ZMUIRoundIndicatorView mIndicator1;
    private ZMUIRoundIndicatorView mIndicator2;
    private Button mBtn;
    private Button mBtn1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_round_indicator);
        findViews();

        mBtn.setOnClickListener(c -> {
            Random random = new SecureRandom();
            int count = random.nextInt(10) + 1;
            mBtn.setText(String.valueOf(count));
            mIndicator1.setCount(count);
            mIndicator2.setCount(count);

        });
        mBtn1.setOnClickListener(c -> {
            int count = mIndicator1.getCount();
            int selection = mIndicator1.getSelection();
            if (selection >= count - 1) {
                selection = 0;
            } else {
                selection++;
            }
            mIndicator1.setSelection(selection);
            mIndicator2.setSelection(selection);

        });

    }

    private void findViews() {
        mIndicator1 = findViewById(R.id.indicator1);
        mIndicator2 = findViewById(R.id.indicator2);
        mBtn = findViewById(R.id.btn);
        mBtn1 = findViewById(R.id.btn1);
    }
}
